package com.youku.plugins.searchBarV4.view
{
   import flash.display.Sprite;
   import flash.display.MovieClip;
   import com.youku.plugins.PluginEventDispather;
   import com.youku.interfaces.IPlayerProxy;
   import flash.utils.Timer;
   import flash.text.TextField;
   import flash.events.Event;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   import flash.events.MouseEvent;
   import flash.events.TimerEvent;
   import com.youku.utils.Tweener;
   
   public class SearchBar extends Sprite
   {
      
      public function SearchBar(param1:IPlayerProxy, param2:PluginEventDispather = null) {
         super();
         this._playerProxy = param1;
         this._pluginEventDispather = param2;
         this.init();
      }
      
      private var _background:MovieClip;
      
      private var _pluginEventDispather:PluginEventDispather;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _timer:Timer;
      
      private var _flag:Boolean;
      
      private var _focusFlag:Boolean;
      
      private var _retainBL:Boolean;
      
      private var _stageWidth:Number;
      
      private var _stageHeight:Number;
      
      private var _isOver:Boolean;
      
      private var _adFlag:Boolean;
      
      private var _textField:TextField;
      
      private var _text:String;
      
      private function init(param1:Event = null) : void {
         this._background = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         this._background.height = 32;
         addChild(this._background);
         this._textField = new TextField();
         this._textField.width = 200;
         this._textField.height = 24;
         this._textField.x = 6;
         this._textField.y = 4;
         this._textField.defaultTextFormat = new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,13421772);
         this.addChild(this._textField);
         this._timer = new Timer(2 * 1000,1);
         this.y = -this.height;
         this.addEvent();
      }
      
      private function addEvent() : void {
         this._playerProxy.addEventListener(MouseEvent.MOUSE_MOVE,this.onMove);
         this._playerProxy.addEventListener(Event.MOUSE_LEAVE,this.onLeave);
         this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
         this.addEventListener(MouseEvent.ROLL_OVER,this.onThisRollOver);
         this.addEventListener(MouseEvent.ROLL_OUT,this.onThisRollOut);
      }
      
      private function onThisRollOut(param1:MouseEvent) : void {
         this._isOver = false;
         if(!this._focusFlag)
         {
            this._timer.reset();
            this._timer.start();
         }
      }
      
      private function onThisRollOver(param1:MouseEvent) : void {
         this._isOver = true;
         this._timer.stop();
      }
      
      private function onTimerComplete(param1:TimerEvent) : void {
         if(!this._retainBL)
         {
            Tweener.to(this,0.5,
               {
                  "y":-36,
                  "alpha":0
               });
            this._flag = false;
         }
      }
      
      private function onMove(param1:MouseEvent) : void {
         if(stage)
         {
            if(!this._adFlag)
            {
               if(stage.mouseY < this._stageHeight / 4)
               {
                  if(!this._focusFlag && !this._isOver)
                  {
                     this._timer.reset();
                     this._timer.start();
                  }
                  if(!this._flag)
                  {
                     Tweener.to(this,0.5,
                        {
                           "y":0,
                           "alpha":1
                        });
                     this._flag = true;
                  }
               }
            }
         }
      }
      
      private function onLeave(param1:Event) : void {
         if(!this._focusFlag)
         {
            if(!this._retainBL)
            {
               Tweener.to(this,0.5,
                  {
                     "y":-36,
                     "alpha":0
                  });
               this._flag = false;
            }
         }
      }
      
      private function removeEvent() : void {
      }
      
      public function changeSize(param1:Number, param2:Number) : void {
         this._stageWidth = param1;
         this._stageHeight = param2;
         this._textField.width = param1;
         this._background.width = param1;
      }
      
      public function uninstall() : void {
         this.removeEvent();
      }
      
      public function show(param1:Boolean = false) : void {
         this._retainBL = param1;
         Tweener.to(this,0.5,
            {
               "y":0,
               "alpha":1
            });
         this._flag = true;
         this._timer.start();
      }
      
      public function set retain(param1:Boolean) : void {
         this._retainBL = param1;
      }
      
      public function set adFlag(param1:Boolean) : void {
         this._adFlag = param1;
      }
      
      public function set text(param1:String) : void {
         this._text = param1;
         this._textField.text = this._text;
      }
   }
}
